<%-- 
/*
Assignment 1
Class ID        : SE0691
Group           : 1
Due Date        : 20 November 2012
I declare that this assignment is my own work
in accordance with FPT Policy.
*/
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="edu.fpt.dal.ServicesDAL"%>
<%@page import="edu.fpt.hib.Services"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.List"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="edu.fpt.dal.UsersDAL"%>
<%@page import="edu.fpt.hib.Users"%>
<%@page import="edu.fpt.dal.ApartmentDAL"%>
<%@page import="edu.fpt.hib.Apartment"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Apartment detail</title>
        <style type="text/css"> <!--@import url("../style.css");--></style>
        <script>function goBack()  {  window.history.back()  }</script>
    </head>
    <body>
        <%@include file="template/header.jsp" %>

        <div id="page">

            <%
                if (ApartmentDAL.getApartmentByID(request.getParameter("apartid")) == null) {
            %>
            Apartment are not in used!
            <input class="searchsubmit" type='button' value='Back' onclick='goBack()'>
            <% } else {
                //Users user = UsersDAL.getUsersHQL(request.getParameter("userid"));
                Apartment apart = ApartmentDAL.getApartmentByID(request.getParameter("apartid"));
                Users user = UsersDAL.getUsersHQL(apart.getUsers().getUserId());
                StringTokenizer stToken = new StringTokenizer(apart.getUsingServices(), " ");
                ArrayList<String> ser = new ArrayList<String>();
                while (stToken.hasMoreElements()) {
                    ser.add(stToken.nextToken().toString());
                }
            %>
            <h2 class="title">Details of : <%=apart.getApartId()%></h2>
            <table border="0">
                <tr>
                    <td>Using by</td>
                    <td><%=user.getUserFullName()%></td>
                </tr>
                <tr>
                    <td>Ownership</td>
                    <td><% if (apart.getIsOwn()) {%> Owner
                        <%} else {%>
                        Tenant
                        <%}
                        %></td>
                </tr>
                <tr>
                    <td>Electric Number</td>
                    <td><%=apart.getElectricNum()%></td>
                </tr>
                <tr>
                    <td>Water Number</td>
                    <td><%=apart.getWaterNum()%></td>
                </tr>
                <tr>
                    <td>Using Services</td>
                    <td><table>
                            <% for (int i = 0; i < ser.size(); i++) {
                                    Services services = ServicesDAL.getByServicesID(ser.get(i));
                                    if(services!=null){
        %>
                                    <tr><td><%=services.getServiceName()%></td><td style="text-align: right;"><%=services.getServicePrice() %></td></tr>
                            <%}}%>
                        </table>

                    </td>
                </tr>
                <% if (!apart.getIsOwn()) {%> 
                <tr>
                    <td>Renting cost</td>
                    <td>3000000</td>
                </tr>
                        <%} %>
            </table>
            <input class="searchsubmit" type='button' value='Back' onclick='goBack()'>
            <%}
            %>
        </div>
        <%@include file="template/footer.jsp" %>
    </body>
</html>
